package com.jiang.service.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiang.dao.INewsDAO;
import com.jiang.service.INewsService;
import com.jiang.vo.News;

@Service
public class NewsServiceImpl implements INewsService {

	@Autowired
	private INewsDAO newsDAO;
	
	@Override
	public boolean insert(News news) {

		boolean flag = false;
		try {
			flag = newsDAO.doCreate(news);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return flag;
	}

	@Override
	public List<News> findSplit(String key, String value, int curpage, int lineSize) {
		
//		SELECT * FROM news WHERE ${key} LIKE #{value} LIMIT #{start},#{lineSize};
		Map<String,Object> param = new HashMap<>();
		param.put("key", key);
		param.put("value", "%"+value+"%");
		param.put("start", (curpage-1)*lineSize);
		param.put("lineSize", lineSize);
		List<News> newses = null;
		try {
			newses = newsDAO.findSplit(param);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return newses;
	}

}
